package model;

import java.io.Serializable;

/**
 * Klasse Packet
 * 
 * @author Magnus Brieler
 */
public class Packet implements Serializable {

	// Attribute
	private PacketType type;
	private User from;
	private Chatroom chatroom;
	private Object content;
	private PacketError error;

	// Konstruktoren
	public Packet() {
		type = null;
		from = new User();
		chatroom = new Chatroom();
		content = new Object();
		error = null;
	}

	public Packet(PacketType type, User from, Chatroom chatroom, Object content) {
		this.type = type;
		this.from = from;
		this.chatroom = chatroom;
		this.content = content;
		error = null;
	}

	public Packet(PacketType type, User from, Chatroom chatroom, Object content, PacketError error) {
		this.type = type;
		this.from = from;
		this.chatroom = chatroom;
		this.content = content;
		this.error = error;
	}

	// Getter
	public PacketType getType() {
		return type;
	}

	public User getFrom() {
		return from;
	}

	public Chatroom getChatroom() {
		return chatroom;
	}

	public Object getContent() {
		return content;
	}
	
	public PacketError getError() {
		return error;
	}

	// Setter
	public void setType(PacketType type) {
		this.type = type;
	}

	public void setFrom(User from) {
		this.from = from;
	}

	public void setChatroom(Chatroom chatroom) {
		this.chatroom = chatroom;
	}

	public void setContent(Object content) {
		this.content = content;
	}
	
	public void setError(PacketError error) {
		this.error = error;
	}
	
	// Methoden

	// enums
	public enum PacketType {
								//**Server**	**Client**
		CHECK(0),				//null			null
		MESSAGE(1), 			//String		String
		LOG(2), 				//boolean		boolean
		CHATROOMCREATECLOSE(3), //boolean		boolean
		CHATROOMENTEREXIT(4), 	//boolean		boolean
		SETCHRONICLE(5), 			//boolean		boolean
		SETPERMANENCY(6), 			//boolean		boolean
		INVITEMEMBER(7), 		//User			User
		KICKMEMBER(8),			//User			User
		MUTEMEMBER(9), 			//User			User
		BANMEMBER(10), 			//User			User
		CHANGEUSERNAME(11), 	//String		String
		CHANGEPASSWORD(12), 	//String		String
		CHANGESTATUS(13), 		//OnlineStatus	OnlineStatus
		ADDFRIEND(14), 			//Friendship	Friendship
		REMOVEFRIEND(15), 		//User			User
		IGNOREUSER(16), 		//User			User
		UNIGNOREUSER(17), 		//User			User
		SEARCHUSER(18), 		//String		*User*
		GETPROFILE(19), 			//User			User
		GETADMINRIGHTS(20), 			//User			User
		GIVEADMINRIGHTS(21), 			//User			User
		TAKEADMINRIGHTS(22),			//User			User
		REGISTER(23),			//null			null
		CLEARCHRONICLE(24),//null null
		CHANGESTATUSMESSAGE(25),//String String
		ADDNOTE(26),//Friendship Friendship
		LOGINCHATROOMS(27),//Chatroom[]
		FRIENDLOG(28),//boolean
		ACCEPTFRIEND(29),//Friendship
		ACCEPTINVITE(30),//null
		LOGINFRIENDREQUESTS(31),//Friendship[]
		PROFILEEDIT(32),//Friendship
		DECLINEFRIEND(33),//User
		//AB HIER NEU
		OPENCHATROOMS(34);//Chatroom[]

		private int index;
		
		public int getIndex() {
			return index;
		}

		private PacketType(int index) {
			this.index = index;
		}
	}
	
	public enum PacketError {
		MISSINGRIGHTS(), WRONGPASSWORD(), UNKNOWNUSER(), ALREADYEXISTS();
	}

}